#import "tool_point.h"

float ptPointDistance_CGPoint(CGPoint Point1, CGPoint Point2)
{
	float _x, _y;

	_x = Point1.x - Point2.x;
	_y = Point1.y - Point2.y;
	return sqrtf(_x * _x + _y * _y);
}

float ptPointDistance_b2Vec2(b2Vec2 Point1, b2Vec2 Point2)
{
	float _x, _y;

	_x = Point1.x - Point2.x;
	_y = Point1.y - Point2.y;
	return sqrtf(_x * _x + _y * _y);
}

b2Vec2 ptRotatePoint_b2Vec2(b2Vec2 In, float Degree)
{
	b2Vec2 _Ret;
	float _Radius = CC_DEGREES_TO_RADIANS(Degree);
	_Ret.x = cos(_Radius) * In.x - sin(_Radius) * In.y;
	_Ret.y = cos(_Radius) * In.y + sin(_Radius) * In.x;
	return _Ret;
}

CGPoint ptRotatePoint_CGPoint(CGPoint In, float Degree)
{
	CGPoint _Ret;
	float _Radius = CC_DEGREES_TO_RADIANS(Degree);
	_Ret.x = cos(_Radius) * In.x - sin(_Radius) * In.y;
	_Ret.y = cos(_Radius) * In.y + sin(_Radius) * In.x;
	return _Ret;
}

b2Vec2 ptConvertCGPoint(CGPoint Point)
{
	return b2Vec2(Point.x, Point.y);
}

b2Vec2 ptConvertCGSize(CGSize Size)
{
	return b2Vec2(Size.width, Size.height);
}

CGPoint ptConvertb2Vec2ToCGPoint(b2Vec2 In)
{
	return ccp(In.x, In.y);
}

CGSize ptConvertb2Vec2ToCGSize(b2Vec2 In)
{
	return CGSizeMake(In.x, In.y);
}

CGPoint ptScalePoint_same(CGPoint Point, float Ratio)
{
	Point.x *= Ratio;
	Point.y *= Ratio;
	return Point;
}

CGPoint ptScalePoint_diff(CGPoint Point, float RatioX, float RatioY)
{
	Point.x *= RatioX;
	Point.y *= RatioY;
	return Point;
}

b2Vec2 ptScaleVector_same(b2Vec2 Vector, float Ratio)
{
	Vector.x *= Ratio;
	Vector.y *= Ratio;
	return Vector;
}

b2Vec2 ptScaleVector_diff(b2Vec2 Vector, float RatioX, float RatioY)
{
	Vector.x *= RatioX;
	Vector.y *= RatioY;
	return Vector;
}

b2Vec2 *ptCreateCollisionVertex(std::vector<CGPoint> *Table)
{
	int i;
	int _Count;
	b2Vec2 *_Ret;

	_Count = Table->size();
	_Ret = (b2Vec2 *)malloc(sizeof(b2Vec2) * _Count);
	for (i = 0; i < _Count; i++)
	{
		_Ret[i] = ptConvertCGPoint((*Table)[i]);
	}
	return _Ret;
}